<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 60px">标签名称:</label>
        <div class="layui-input-inline">
            <input type="text" name="dictPrompt" id="dictPrompt" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label" style="width: 40px">类别:</label>
        <div class="layui-input-inline">
            <select name="dictEntry" id="dictEntry">
                <option value="">全部</option>
                <option value="basic_equipment">基础设备</option>
                <option value="bathroom_equipment">卫浴设备</option>
                <option value="household_equipment">家用电器</option>
                <option value="general_equipment">通用设施</option>
                <option value="service_equipment">服务项目</option>
            </select>
        </div>
        <button class="layui-btn" id="searchBtn" lay-submit lay-filter="searchBtn">查询</button>
        <button class="layui-btn" lay-submit lay-filter="addBtn" id="addBtn">新增标签</button>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var btnRight;
    var tableIns;
    var isSuper = 0;

    $(function () {
        tableIns = createTable({
            url: 'list',
            cols: [[{field: 'id', title: '编号', width: 120},
                {field: 'dictPrompt', title: '标签名称', width: 150}
                , {
                    field: 'dictEntry',
                    title: '标签大类',
                    width: 150,
                    templet: '#sortTpl'
                }, {
                    field: 'delBoolean',
                    title: '状态',
                    width: 100,
                    templet: '#statusTpl'
                }, {
                    fixed: 'right',
                    title: '操作',
                    width: 200,
                    align: 'center',
                    toolbar: '#opbar'
                }
            ]]
        })
    });

    layui.table.on('tool(grid)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值
        var tr = obj.tr; //获得当前行 tr 的DOM对象02\
        if (layEvent === 'change') { //删除
            changeStatus(data.id, data.delBoolean);
        } else if (layEvent === 'edit') { //编辑
            openDialog({
                url: "/backend/security/sysDictionary/detail?id=" + data.id
            });
        }
    });

    //变更标签状态
    function changeStatus(id, status) {
        if (status == "0") {
            $.post('/backend/security/sysDictionary/update', {id: id, delBoolean: 1}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("禁用成功");
                        tableIns.reload();
                    }
                }
            )
        } else if (status = "1") {
            $.post('/backend/security/sysDictionary/update', {id: id, delBoolean: 0}, function (res) {
                    if (res.code < 0) {
                        layer.msg(res.message);
                    }
                    else {
                        layer.msg("启用成功");
                        tableIns.reload();
                    }
                }
            )
        }
    }

    layui.form.on('submit(addBtn)', function () {
        openDialog({
            url: "/backend/security/sysDictionary/detail",
            btn: ["保存", "取消"]
        });
        return false;
    });

    layui.form.on('submit(searchBtn)', function (data) {
        tableIns.reload({
            where: data.field
        });
        return false;
    });
</script>
<script type="text/html" id="sortTpl">
    {{#  if(d.dictEntry ==="basic_equipment"){ }}
    <span>基础设备</span>
    {{#  } else if(d.dictEntry ==="bathroom_equipment"){ }}
    <span>卫浴设备</span>
    {{#  } else if(d.dictEntry ==="household_equipment"){ }}
    <span>家用电器</span>
    {{#  } else if(d.dictEntry ==="general_equipment"){ }}
    <span>通用设施</span>
    {{#  } else if(d.dictEntry ==="service_equipment"){ }}
    <span>服务项目</span>
    {{#  } }}
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status ===1){ }}
    <span style="color: #FF0000;">下架</span>
    {{#  } else { }}
    <span style="color: green;">上架</span>
    {{#  } }}
</script>
<script type="text/html" id="opbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="change">变更状态</a>
</script>
</body>
</html>
